//
//  KDMypatientTableViewCell.m
//  LaiKeDaoClient
//
//  Created by dongkedi的iMac on 15/11/11.
//  Copyright © 2015年 LKD. All rights reserved.
//

#import "KDMypatientTableViewCell.h"
#import "UIImageView+WebCache.h"
@implementation KDMypatientTableViewCell
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createUI];
    }
    return self;
}

- (void)createUI
{
    self.headImageView = [[UIImageView alloc] initWithFrame:(CGRect){10,5,44,44}];
    [self.headImageView setImage:[UIImage imageNamed:@"ic_pic.png"]];
    self.headImageView.layer.cornerRadius = 5;
    self.headImageView.layer.masksToBounds = YES;
    [self.contentView addSubview:_headImageView];
    
    self.nameLabel = [[UILabel alloc] initWithFrame:(CGRect){X(_headImageView)+WIDTH(_headImageView)+10,Y(_headImageView),200,20}];
    [_nameLabel setTextAlignment:NSTextAlignmentLeft];
    [_nameLabel setFont:[UIFont systemFontOfSize:16]];
    [_nameLabel setBackgroundColor:[UIColor clearColor]];
    [_nameLabel setText:@"姓名  性别  年龄"];
    [self.contentView addSubview:_nameLabel];
    
    self.timeLabel = [[UILabel alloc] initWithFrame:(CGRect){kScreenWidth-60,Y(_headImageView),50,20}];
    [_timeLabel setTextAlignment:NSTextAlignmentRight];
    [_timeLabel setFont:[UIFont systemFontOfSize:12]];
    [_timeLabel setBackgroundColor:[UIColor clearColor]];
    [_timeLabel setTextColor:[UIColor colorWithHexString:@"cccccc"]];
    [_timeLabel setText:@"10:01"];
    [self.contentView addSubview:_timeLabel];
    
    self.addLabel = [[UILabel alloc] initWithFrame:(CGRect){kScreenWidth-60,28,50,20}];
    [_addLabel setTextAlignment:NSTextAlignmentRight];
    [_addLabel setFont:[UIFont systemFontOfSize:12]];
    [_addLabel setBackgroundColor:[UIColor clearColor]];
    [_addLabel setTextColor:[UIColor colorWithHexString:@"cccccc"]];
    [_addLabel setText:@"未添加"];
    [self.contentView addSubview:_addLabel];
}

- (void)reloadData:(LKDPatientListDetailModel    *)dataDic
{
    [_headImageView setImageWithURLString:dataDic.head_ico];
    _nameLabel.text = [NSString stringWithFormat:@"%@  %@  %@岁",dataDic.name,dataDic.sex,dataDic.age];
    _timeLabel.text = dataDic.create_time;
    _addLabel.text = dataDic.status_text;
    [self tagView:dataDic.tag_list];
}

- (void)tagView:(NSArray *)textArray{
    UIView *bgView = [[UIView alloc] initWithFrame:CGRectZero];
    bgView.backgroundColor = [UIColor clearColor];
    
    CGFloat total_x = 0.0f, labelH = HEIGHT(_nameLabel);
    for (int i=0; i<textArray.count; ++i) {
        NSString *msgString = textArray[i];
        
        CGFloat padding_x = 5.0f;
        
        // iOS7depre
        CGSize size = [msgString sizeWithFont:[UIFont systemFontOfSize:12.0f]
                            constrainedToSize:CGSizeMake(250.0f, labelH) lineBreakMode:NSLineBreakByWordWrapping];
        size.width += 10;
        UILabel *label1 = [[UILabel alloc] initWithFrame:(CGRect){total_x,0,size.width,labelH}];
        [label1 setText:msgString];
        [label1 setTextAlignment:NSTextAlignmentCenter];
        [label1 setFont:[UIFont systemFontOfSize:12]];
        [label1 setTextColor:[UIColor colorWithHexString:@"333333"]];
        [label1 setBackgroundColor:[UIColor colorWithHexString:@"dddddd"]];
        [bgView addSubview:label1];
        label1.layer.cornerRadius = 5;//设置那个圆角的有多圆
        label1.layer.masksToBounds = YES;
        
        total_x = total_x + (size.width+padding_x);//累加
    }
    
    bgView.frame = CGRectMake(X(_nameLabel), Y(_nameLabel)+HEIGHT(_nameLabel), SCREEN_WIDTH, labelH);//
    [self.contentView addSubview:bgView];
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
